convert int to text or string

I'm trying put a interger to a text attribute. Can't seem to figure out how to convert interger to text or string. Any help would be appreciated. Thanks!
DOORS_USER - Fri May 14 11:34:20 EDT 2010

Re: convert int to text or string
DOORS_USER - Fri May 14 12:10:24 EDT 2010

Here is the code...
 

Module m = current 
Object o
string objText
 
if ( null m )
{ //
    ack "Please open a module first."
    halt
}
 
for o in m do {
  objText = o."SRC_ID"
 
  if (isValidInt(objText))
    if(intOf(objText)>0)
    {
    int src_id = intOf(objText)-55
      o."SRC_ID" = src_id                     //ERROR: expected int attribute
    } 
}

Re: convert int to text or string
SystemAdmin - Fri May 14 12:50:24 EDT 2010

DOORS_USER - Fri May 14 12:10:24 EDT 2010

Here is the code...
 

Module m = current 
Object o
string objText
 
if ( null m )
{ //
    ack "Please open a module first."
    halt
}
 
for o in m do {
  objText = o."SRC_ID"
 
  if (isValidInt(objText))
    if(intOf(objText)>0)
    {
    int src_id = intOf(objText)-55
      o."SRC_ID" = src_id                     //ERROR: expected int attribute
    } 
}

Hi DOORS USER!

Normally the only thing you have got to do ist to concatenate the integer-value with an empty string: ""
 

Module m = current 
Object o
string objText
 
if ( null m )
{ //
    ack "Please open a module first."
    halt
}
 
for o in m do {
  objText = o."SRC_ID"
 
  if (isValidInt(objText))
    if(intOf(objText)>0)
    {
    int src_id = intOf(objText)-55
      o."SRC_ID" = src_id ""                        //ERROR: expected int attribute
      /* Concatenation with an empty string */
    } 
}

 


You are shure, your Attribute ist based on Text or String?
Your errormessage looks like the problem might be based somewhere else...

 

Re: convert int to text or string
llandale - Fri May 14 13:03:09 EDT 2010

Yes, turning things into strings is usually done by concatenating it with an empty string. obj."SRC_ID" = srcId "".

Looks to me like your SRC_ID attribute should be type 'Integer', in which case you read it into an int variable, subtract 55, and put it back.

  • Louie

Re: convert int to text or string
Mathias Mamsch - Sat May 15 09:07:40 EDT 2010

DOORS_USER - Fri May 14 12:10:24 EDT 2010

Here is the code...
 

Module m = current 
Object o
string objText
 
if ( null m )
{ //
    ack "Please open a module first."
    halt
}
 
for o in m do {
  objText = o."SRC_ID"
 
  if (isValidInt(objText))
    if(intOf(objText)>0)
    {
    int src_id = intOf(objText)-55
      o."SRC_ID" = src_id                     //ERROR: expected int attribute
    } 
}

You should also note that the isValidInt function does not behave as you would expect (if your string contains only of whitespaces) ... So you might want to put a check there ...
 

string s = " "
    
    if (isValidInt s) {
        print "Cewl, its valid!" 
 
        intOf s // argh, it isnt ... :-(
    }

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: convert int to text or string
llandale - Mon May 17 12:09:36 EDT 2010

Mathias Mamsch - Sat May 15 09:07:40 EDT 2010

You should also note that the isValidInt function does not behave as you would expect (if your string contains only of whitespaces) ... So you might want to put a check there ...
 

string s = " "
    
    if (isValidInt s) {
        print "Cewl, its valid!" 
 
        intOf s // argh, it isnt ... :-(
    }

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Here's my two functions that do the conversions.

//***************
bool    fIsValidInt(string InString)
{     // Is the string a valid positive or negative integer?
        // InString must be digits, optionally preceded with a dash "-", e.g. "-123";
        //    must not have commas, e.g. "12,345".
        // Developer's note: Null strings return false here, whereas "isValidInt" returns true.
        if (null InString or !isValidInt(InString))
             return(false)
        else return(true)
}     // end fIsValidInt()
 
//***************
bool    fStringToInt(string InString, int &OutInt)
{     // Convert the InString to a valid Integer.  Return whether it worked.
        // Improper or null Strings return False and Zero
        // Max int is about 10 digits (system limitation in DOORS v7.1)
        if (!fIsValidInt(InString))
        {  OutInt = 0
           return(false)
        }
        else
        {  OutInt = intOf(InString)
           return(true)
        }
}     // end fStringToInt()

 

  • Louie